﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TDD.SpreadSheet.Exceptions;

namespace TDD.SpreadSheet
{
    internal class Operator
    {
        public Operator()
        {
        }

        public Operator(char name)
        {
            Name = name;
            switch (Name)
            {
                case '*':
                case '/':
                    Order = 1;
                    break;
                case '-':
                case '+':
                    Order = 2;
                    break;
                default:
                    throw new ArgumentException("Current operator is not a valid operator.", "currentOperator");
            }
        }

        public int Order
        { get; set; }
        public char Name
        { get; set; }

        public decimal Calculate(decimal valueA, decimal valueB)
        {
            switch (Name)
            {
                case '*':
                    return valueA * valueB;
                case '/':
                    if (valueB == 0)
                    {
                        throw new InvalidFormulaException("There is a mistake in the formula");
                    }
                    return valueA / valueB;
                case '-':
                    return valueA - valueB;
                case '+':
                    return valueA + valueB;
                default:
                    throw new ArgumentException("Current operator is not a valid operator.", "currentOperator");
            }
        }
    }
}
